package com.lagou.wang.dao.user;



import com.lagou.wang.pojo.User;
import com.lagou.wang.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;


import java.sql.SQLException;


/**
 * @author wanggege
 * UserDao实现类
 */
public class UserDaoImpl implements UserDao {

    /**
     * @param user
     * @return
     * 实现登录与数据库进行校验
     */
    @Override
    public User userLogin(User user) {
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
        String sql = "select * from t_user where userName = ? and password = ?";
        Object[] param = {user.getUserName(),user.getPassword()};
        try {
            User user1 = qr.query(sql, new BeanHandler<User>(User.class), param);
            return user1;
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {

        }
        return null;
    }



}
